package com.xincongjun.media.utils;

import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

import static com.xincongjun.media.utils.DateTimeUtil.STANDARD_TIME_PATTERN;
import static com.xincongjun.media.utils.DateTimeUtil.toUtcIso8601;


public class POIUtil {

    private static final Logger logger = LoggerFactory.getLogger(POIUtil.class);

    public static void usePOIUpdateTime(String filePath, String timeString)  {
        File file = new File(filePath);
        timeString = toUtcIso8601(timeString, STANDARD_TIME_PATTERN);

        try (OPCPackage pkg = OPCPackage.open(file)) {
            PackageProperties props = pkg.getPackageProperties();

            props.setCreatedProperty(timeString);
            props.setModifiedProperty(timeString);
        }catch (Exception e) {
            throw new RuntimeException("执行 PowerShell 命令失败：" + filePath, e);
        }
    }


}
